function getRandomColor() {
  const rgb = []
  for (let i = 0; i < 3; ++i) {
    let color = Math.floor(Math.random() * 256).toString(16)
    color = color.length === 1 ? '0' + color : color
    rgb.push(color)
  }
  return '#' + rgb.join('')
}
var t = getApp()
Page({
  
  inputValue: '',
  data: {
    src: '',
    iconsUrl:t.globalData.iconsUrl,
    danmuList:
    [{
      text: '第 1s 出现的弹幕',
      color: '#ff0000',
      time: 1
    }, {
      text: '第 3s 出现的弹幕',
      color: '#ff00ff',
      time: 3
    }],
    url:'',
    navHeight:t.globalData.navHeight,
    title:'操作说明',
  },
  onShareAppMessage() {
    return {
      title: 'video',
      path: 'page/component/pages/video/video',
      list:[],
    }
  },
  onLoad: function (options) {

  },
  onShow(e){
    this.setData({
      userInfo:wx.getStorageSync('userInfo'),
    })
    this.getall();
    this.getsite();
  },
  onRefresh(){
    //在当前页面显示导航条加载动画
    wx.showNavigationBarLoading(); 
    //显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框
    this.getall();
  },
  onPullDownRefresh: function () {
    //调用刷新时将执行的方法
    this.onRefresh();
    setTimeout(function () {
      // 不加这个方法真机下拉会一直处于刷新状态，无法复位
      wx.stopPullDownRefresh()
    }, 1000)
  },
  getall(){
    let that=this;
    t.request('/Users/getproblem',{},function(r){
          console.log(r.result);
          that.setData({
            list:r.result
          })
    })
  },
  getsite(){
    let that=this;
    t.request('/Users/getEntry',{},function(r){
          console.log(r.result);
          that.setData({
            url:r.result.video_address
          })
    })
  },
  onReady() {
    this.videoContext = wx.createVideoContext('myVideo')
  },

  onHide() {

  },


  bindInputBlur(e) {
    this.inputValue = e.detail.value
  },

  bindButtonTap() {
    const that = this
    wx.chooseVideo({
      sourceType: ['album', 'camera'],
      maxDuration: 60,
      camera: ['front', 'back'],
      success(res) {
        that.setData({
          src: res.tempFilePath
        })
      }
    })
  },

  bindVideoEnterPictureInPicture() {
    console.log('进入小窗模式')
  },

  bindVideoLeavePictureInPicture() {
    console.log('退出小窗模式')
  },

  bindPlayVideo() {
    console.log('1')
    this.videoContext.play()
  },
  bindSendDanmu() {
    this.videoContext.sendDanmu({
      text: this.inputValue,
      color: getRandomColor()
    })
  },

  videoErrorCallback(e) {
    console.log('视频错误信息:')
    console.log(e.detail.errMsg)
  }
})